<template>
    <div id="home" style="margin-bottom: 60px">
        <van-search class="search" placeholder="请输入搜索关键词" v-model="value" @search="onSearch"/>
        <div style="margin-top: 45px; ">
            <van-swipe :autoplay="3000">
                <van-swipe-item v-for="(banner, index) in banners" :key="index">
                    <img :src="banner.banner" style="height: 120px;width: 100%;" @click="goShopping(banner.id)"/>
                </van-swipe-item>
            </van-swipe>
            <van-row>
                <van-col span="8" v-for="(fixedAd, index) in fixedAds" :key="index">
                    <div style="padding:0 1px;">
                        <img :src="fixedAd.picture" style="width: 100% " @click="goShopping(fixedAd.id)"/>
                    </div>
                </van-col>
            </van-row>
            <div>
                <van-tabs v-model="active">
                    <van-tab title="特价"  class="tab">
                        <div v-for="(spec, index) in specialPrice" :key="index">
                            <img :src="spec.picture" style="width: 20%;float: left" @click="goShopping(spec.id)"/>
                        </div>
                    </van-tab>
                    <van-tab title="热销" class="tab">
                        <div  v-for="(h, index) in hot" :key="index">
                            <img :src="h.picture" style="width: 20%;float: left" @click="goShopping(h.id)"/>
                        </div>
                    </van-tab>
                    <van-tab title="好评" class="tab">
                        <div  v-for="(pra, index) in praise" :key="index">
                            <img :src="pra.picture" style="width: 20%;float: left" @click="goShopping(pra.id)"/>
                        </div>
                    </van-tab>
                </van-tabs>
            </div>
            <div style="margin-top: 100px"></div>
            <div v-for="floor in floors">
                <van-panel :title="floor.floorName" desc="" :status="floor.rightTag +'>'" >
                    <div style="padding: 5px 20px" >
                        <van-row :gutter="20">
                            <van-col  v-for="(item,index) in floor.floorAdvertVOS" span="8" style="border: 1px solid #eee;border-left:none; padding: 5px">
                                <img :src="item.imageUrl" @click="goShopping(item.id)"/>
                            </van-col>
                            <van-col span="8" style="text-align: center;border-top: 1px solid #eee; color: #888; font-weight: 600">
                                <div style="margin-top: 47%;" @click="clickMore(floor.floorGoodsVOS[8].brandId)">更多</div>
                            </van-col>
                        </van-row>
                        <van-row :gutter="20">
                            <template v-for="(item,index) in floor.floorGoodsVOS" v-if="index<8">
                            <van-col span="6" class="border" :class="{'no-border-right': (index+1)%4===0 }">
                                <img style="" :src="item.imageUrl" @click="goShopping(item.id)" />
                                <div style="font-size: 2px; line-height: 12px; overflow-y: hidden; height: 12px ;font-size: 12px; color: #888; font-weight: 700">{{item.goodsName}}</div>
                                <div style="font-size: 2px; line-height: 12px; overflow-y: hidden; color: red; height: 12px ;font-size: xx-small;margin-top: 3px;">￥{{item.price}}</div>
                            </van-col>
                            </template>
                        </van-row>
                    </div>
                </van-panel>
            </div>
        </div>

    </div>
</template>

<script>
    import {listAds,listGoods} from '../../api/advert'
    export default {
        data() {
            return {
                active: '',
                value: '',
                banners: {},
                fixedAds: {},
                floors: {},
                specialPrice: {},
                hot: {},
                praise: {},
            }
        },
        mounted() {
            listAds(d => {
                if (d) {
                    //轮播图
                    this.banners = d.banners.banners
                    // console.log("==="+JSON.stringify(d))
                    //固定广告位
                    this.fixedAds = d.advertisement.pictures
                    //特价
                    this.specialPrice = d.popular.specialPrice
                    //热销
                    this.hot = d.popular.sellWell
                    //好评
                    this.praise = d.popular.favorableComment
                    //楼层
                    this.floors = d.floor
                }

            })
        },
        methods: {
            onSearch() {
                this.$router.push({path: 'search', query: {name: this.value}});
            },
            goShopping(id) {
                this.$router.push('/goods/'+id);
            },
            clickMore(id) {
                this.$router.push({path: 'search', query: {brandId: id}});
            }

        }
    }
</script>

<style lang="less" scoped>

    .tab{
        padding-top: 10px;
    }
    .border{
        border: 1px solid #eee;
        border-left:none;
        text-align: center;
        padding: 5px;
    }
    .no-border-right{
        border-right:none ;
    }
    .user {

        &-group {
            margin-bottom: .3rem;
        }
        &-links {
            padding: 15px 0;
            font-size: 12px;
            text-align: center;
            background-color: #fff;

            .van-icon {
                display: block;
                font-size: 24px;
            }
        }
    }
</style>

<style lang="less">
    #home {
        .van-search {
            position: fixed;
            z-index: 100;
            width: 100%;
            top: 0;
        }
        .van-search .van-cell {
            border-radius: 15px;
        }
    }
</style>